<?php
/*
	Class responsable to proceess images(resize, move, copy)
*/
class Image
{
	function resampimagejpg( $forcedwidth, $forcedheight, $sourcefile, $destfile_name )
	{
		$uploadedfile = $sourcefile;
		$src = imagecreatefromjpeg($uploadedfile);
		list($width,$height)=getimagesize($uploadedfile);
		if( $width > $height)
		{
			$ratio = $width/$height;
			$newwidth=$forcedwidth;
			$newheight=round($forcedwidth / $ratio);
		}
		else
		{
			$ratio = $height/$width;
			$newwidth=$forcedwidth;
			$newheight=round($forcedwidth * $ratio);
		}
		$tmp=imagecreatetruecolor($newwidth,$newheight);
		imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height); 
		$filename = $destfile_name;
		imagejpeg($tmp,$filename,100);
		imagedestroy($src);
		imagedestroy($tmp);
	}
	
	function resampjpg_noratio( $forcedwidth, $forcedheight, $sourcefile, $destfile_name )
	{
		$uploadedfile = $sourcefile;
		$src = imagecreatefromjpeg($uploadedfile);
		list($width,$height)=getimagesize($uploadedfile);
		$newwidth=$forcedwidth;
		$newheight=$forcedheight;		
		$tmp=imagecreatetruecolor($newwidth,$newheight);
		imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height); 
		$filename = $destfile_name;
		imagejpeg($tmp,$filename,100);
		imagedestroy($src);
		imagedestroy($tmp);
	}
}
?>